//
//  mainViewController.swift
//  新浪微博
//
//  Created by zero on 15/8/1.
//  Copyright © 2015年 zero. All rights reserved.
//

import UIKit

class mainViewController: UITabBarController {

     override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewControllers()
       
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
       setupComposeButton()
        
    }
    private func setupComposeButton() {
        let w = tabBar.bounds.width / CGFloat(childViewControllers.count)
        let rect = CGRect(x: 0, y: 0, width: w, height: tabBar.bounds.height)
        
        composeButton.frame = CGRectOffset(rect, 2 * w, 0)
    }
    
    
    private func addChildViewControllers() {
          
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(UIViewController())
        addChildViewController(DiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileViewController(), title: "我", imageName: "tabbar_profile")
     
        
    }
    
    
    private func addChildViewController(vc:UIViewController,title:String,imageName:String) {
        
        let vc = vc
        let nav = UINavigationController(rootViewController: vc)
      
        addChildViewController(nav)
        vc.title = title
        vc.tabBarItem.image=UIImage(named:imageName)
        //nav.tabBarItem.title="dasd"
     
    }
    
    //MARK: - 懒加载控件
    lazy private var composeButton:UIButton = {

       let button = UIButton()
       
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        self.tabBar.addSubview(button)
       button.addTarget(self, action:"Ciclkcompose", forControlEvents: UIControlEvents.TouchUpInside)
        
       return button
        }()
    
    

    func Ciclkcompose(){
    
    print("s")
    }
    

}
